
#define _CRT_SECURE_NO_WARNINGS 2

#include<stdio.h>
#include<stdlib.h>

void Swap(int* a, int* b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void QuickSortThree(int* a, int left, int right) {
	if (left >= right) {
		return;
	}
	int key = a[left];
	int begin = left;
	int cur = left + 1;
	int end = right;
	while (cur <= end) {
		if (a[cur] > key) {
			Swap(&a[cur], &a[end--]);
		}
		else if (a[cur] == key) {
			cur++;
		}
		else {
			Swap(&a[cur++], &a[begin++]);
		}
	}
	QuickSortThree(a, left, begin-1);
	QuickSortThree(a, end+1, right);
}

int main() {
	int arr[] = { 3,3,2,4 };
	int len = sizeof(arr) / sizeof(arr[0]);
	QuickSortThree(arr, 0, len - 1);
	for (int i = 0; i < len; i++) {
		printf("%d ", arr[i]);
	}
	return 0;
}